<!DOCTYPE html>
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
  <title>申请内测</title>
    <link href="/stylesheets/mystyle.css" rel="stylesheet">
    <link href="/stylesheets/style.css" rel="stylesheet">
    <script src="/javascripts/jquery.js" charset="utf-8"></script>
    <script src="/javascripts/flexiable.js" charset="utf-8"></script>
    <style media="screen">
  body {
      padding:0;
      margin: 0;
  }
  input {
      padding-left: 10px;
  }
  </style>
  <script type="text/javascript">
//      setInterval("refresh()",60*1000);
//      function refresh() {
//          var vcr=document.getElementById("validateCodeRegister");
//          vcr.src = '/invitecode?t=' + Math.random();
//      }
        window.toast=function(content, time, callback){
            var toastDom = [
                '<div class="toastWrap">',
                '<div class="toastTitle">' + content + '</div>',
                '</div>'
            ].join(''), $toastDom = $(toastDom);

            $('body').append($toastDom);

            if(time){
                setTimeout(function(){
                    $toastDom.remove();
                    (callback && typeof(callback) === "function") && callback();
                }, time );
            }else{
                (callback && typeof(callback) === "function") && callback();
            }
        }

      function changeLoginPage(){
          window.location.href='http://mobileplus.yonyou.com/register?type=login';
      }
      function register() {
          var flag = true;
        var username = $('input').eq(0).val();
        var phone = $('input').eq(1).val();
        var email = $('input').eq(2).val();
          var company = $('input').eq(3).val();
        var inviteCode = $('#invitereason').val();
          clearState();
       // var validateCode = $('input').eq(3).val();

          if (!username) {
            //console.log('用户名不能为空');

            $('#message-name').prev().addClass('error')
            $('#message-name').attr('style','display:block');
            $('#message-name').html('用户名不能为空')
            return;
        }
          if (!phone||!/^1[3|4|5|7|8]\d{9}$/.test(phone)) {
            //console.log('手机不正确');
              $('#message-phone').prev().addClass('error')
              $('#message-phone').attr('style','display:block');
              $('#message-phone').html('手机不正确')
            return;
        }
          if (!email||!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email)) {
              $('#message-email').prev().addClass('error')
              $('#message-email').attr('style','display:block');
              $('#message-email').html('邮箱不能为空')
              return;
          }
          if (!company) {
              //console.log('用户名不能为空');

              $('#message-company').prev().addClass('error')
              $('#message-company').attr('style','display:block');
              $('#message-company').html('单位名称不能为空')
              return;
          }
          if (!inviteCode) {
              $('#message-invitereason').prev().addClass('error')
              $('#message-invitereason').attr('style','display:block');
              $('#message-invitereason').html('申请理由不能为空')
              return;
          }
          function clearState() {
              $('#message-name').prev().removeClass('error')
              $('#message-name').attr('style', 'display:none');
              $('#message-phone').prev().removeClass('error')
              $('#message-phone').attr('style', 'display:none');
              $('#message-email').prev().removeClass('error')
              $('#message-email').attr('style', 'display:none');
              $('#message-company').prev().removeClass('error')
              $('#message-company').attr('style', 'display:none');
              $('#message-invitereason').prev().removeClass('error')
              $('#message-invitereason').attr('style', 'display:none');
              $('#message-code').prev().removeClass('error')
              $('#message-code').attr('style', 'display:none');
          }
          $.post(window.location.protocol+"//"+window.location.host+window.location.pathname+'mobile'+'?'+$("#collector").serialize(),function(data){
             // console.log(data);
               if(data.code==-1){
                   //alert(data.error.msg);
                   window.toast(data.error.msg,1500);
               }else{
                   //console.log(data.success.msg);
                   window.toast(data.success.msg,1000,function(){
                       history.go(0);
                   });

               }
          });

      }
  </script>
</head>
<body>
  <div class="content">

      <form id='collector' class="" method="POST">
          <!--<div class="title">申请内测</div>-->
          <div class="logo"><img src="/images/logo.png"></div>
          <div class="context">
              <div>

                  <div class="item icon-ab-username">
                      <input type="text" name="username" placeholder="请输入姓名">
                  </div>
              </div>
              <div class="message" id="message-name">姓名不能为空</div>
              <div>

                  <div class="item icon-ab-phoneNemble">
                      <input type="number" name="phone" placeholder="请输入手机">
                  </div>
              </div>
              <div class="message" id="message-phone">手机不能为空</div>
              <div>
                  <div class="item icon-ab-mail">
                      <input type="email" name="email" placeholder="请输入邮箱">
                  </div>
              </div>
              <div>
                  <div class="item icon-ab-head-home">
                      <input type="text" name="company" placeholder="请输入单位名称">
                  </div>
              </div>
              <div class="message" id="message-company">单位名称不能为空</div>

              <div class="invitereason-item">
                      <textarea id="invitereason" type="text"  name="invitereason" class="inviteCode" placeholder="请输入内测案例描述"></textarea>
              </div>
              <div class="message" id="message-invitereason">内测案例描述不能为空</div>
              <!--<div style="margin-right: 4px;">-->
                  <!--<input type="text" name="validateCode" class="validateCode" placeholder="请输入验证码">-->
                  <!--&lt;!&ndash; <img width="125px;height:36px;" src="/validateCode" id='validateCodeRegister' onclick="refresh(this)" /> &ndash;&gt;-->
                  <!--<img width="125px;height:36px;" src="/invitecode" id="validateCodeRegister" onclick="refresh(this)">-->
                  <!--<div class="message" id="message-code">验证码不能为空</div>-->
              <!--</div>-->
              <div class="commit-button" onclick="register()">
                  立即申请
                  <!-- <button name='register' id="registerId">立即注册</button> -->
              </div>
          </div>
      </form>
  </div>
  </body>
</html>